#include "accelerometer.h"
#include "display.h"
#include "error.h"
#include "h01.h"
#include "iic.h"
#include "reports.h"
#include "rtc.h"
#include "usb.h"
#include "vx.h"

uint	timeOfs;
uint	timer;
uint	curSteps;
uint	systick;
ushort	error;
ushort	flags;
ushort	ordBase=0x8800;
ubyte	status;
ubyte	clrSteps;
REPORTS reports={RPT_VERSION,0,
	RPT_TICKLO,0,	RPT_TICKHI,0,
	RPT_OFFSETLO,0,	RPT_OFFSETHI,0,
	RPT_VOLTB,0,	RPT_VOLTC,0,	RPT_VOLTS,3300,	
	RPT_TKCHGL,0,	RPT_TKCHGH,0,
	RPT_TCCHGC,0,	RPT_TCCHGV,0,
	RPT_STEPSLO,0,	RPT_STEPSHI,0,
	RPT_ACCKLO,0,	RPT_ACCKHI,0,
};
SAVE	savRam;
Jump*	tagetBas=(Jump*)0x08008800;

static void testH01(void){
	init(RCC_SYSCLK_Div512);
	if(SystemCoreClock!=48000000)
		error |=ERROR_SYSCLK;
	watchdogOn();
	if(usbNoPower())
		PWR_EnterSTANDBYMode();
	RCC_HCLKConfig(RCC_SYSCLK_Div2);
}

//------------------------------------------------------------------------------

void initVecTable(void){
	NVIC_SetVectorTable(NVIC_VectTab_FLASH,0);
}
void main(void){
	testH01();
	displayOn();
	timer=0;
	while(1){
		IWDG_ReloadCounter();	// feed dog
		if(usbNoPower()){
			if(timer<120000)
				outTime(585);
			else PWR_EnterSTANDBYMode();
		}else outBattery(4);
		__WFI();
	}
}